home *** CD-ROM | disk | FTP | other *** search
- Path: connix.com!news
- From: Scott Hawley <shawley@connix.com>
- Newsgroups: comp.lang.c
- Subject: Re: Determining the length of an int in string form
- Date: Fri, 15 Mar 1996 10:57:26 -0800
- Organization: SHAWLEY SYSTEMS
- Message-ID: <3149BD96.572@connix.com>
- References: <Pine.A32.3.91.960313161835.90740D-100000@red.weeg.uiowa.edu>
- NNTP-Posting-Host: shawley.connix.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (Win16; I)
-
- or maybe:
-
- int NumLen( int n )
- {
- if(n > 9999)return(5);
- if(n > 999)return(4);
- if(n > 99)return(3);
- if(n > 9)return(2);
- return(1);
- }
-
- or
-
- int NumLen( int n)
- {
- int digits,ct;
- ct = 9999;
- for(digits = 5; digits > 1; digits--) {
- if(n > ct)break;
- ct - (int)(ct / 10);
- }
- return(digits);
- }
-
- Just some other thoughts
-